/**
 *选择势力画面 
 **/
function SelectMap(){
	var self = this;
	base(this,LSprite,[]);
	self.graphics.drawRect(1,"#000000",[0,0,LGlobal.width,LGlobal.height],true,"#000000");
	self.selectIndex = 0;
	self.selectedIndex = 0;
	self.layerInit();
	self.showBack();
	self.showList();
	self.showMiniMap();
	self.showSelected();
	self.showNextButton();
}
SelectMap.prototype.showSelected=function(index){
	selectedLayer.die();
	selectedLayer.removeAllChild();

	var self = this;
	if(!index)index = 0;
	self.selectedIndex = index;
	var selectMonarch = monarch[self.selectedIndex];
	var chara = characterList[selectMonarch.monarchIndex];
	var face = new Face(chara.img);
	face.x = 565;
	face.y = 20;
	selectedLayer.addChild(face);

	selectedLayer.graphics.drawRect(0,"#000000",[190,10,16,16],true,selectMonarch.color);
	var nameTxt = new LTextField();
	nameTxt.text = chara.name;
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 220;
	nameTxt.y = 10;
	selectedLayer.addChild(nameTxt);

	var nameTxt = new LTextField();
	nameTxt.text = "所选君主";
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 670;
	nameTxt.y = 40;
	selectedLayer.addChild(nameTxt);

	var nameTxt = new LTextField();
	nameTxt.text = chara.name;
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 670;
	nameTxt.y = 80;
	selectedLayer.addChild(nameTxt);

	var nameTxt = new LTextField();
	nameTxt.text = "武将数";
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 570;
	nameTxt.y = 150;
	selectedLayer.addChild(nameTxt);

	var nameTxt = new LTextField();
	nameTxt.text = 3;
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 570;
	nameTxt.y = 180;
	selectedLayer.addChild(nameTxt);

	var nameTxt = new LTextField();
	nameTxt.text = "城池数";
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 570;
	nameTxt.y = 230;
	selectedLayer.addChild(nameTxt);

	var nameTxt = new LTextField();
	nameTxt.text = 2;
	nameTxt.color = "#FFFFFF";
	nameTxt.size = 14;
	nameTxt.x = 570;
	nameTxt.y = 260;
	selectedLayer.addChild(nameTxt);
};
SelectMap.prototype.showBack=function(){
	var bar = getBar(170,310);
	bar.x=5;
	bar.y=5;
	backLayer.addChild(bar);
	bar = getBar(240,310);
	bar.x=550;
	bar.y=5;
	backLayer.addChild(bar);
};
SelectMap.prototype.showNextButton=function(){
	var self = this;
	selectButton = getButton01("上");
	selectButton.x = 25;
	selectButton.y = 320;
	selectButton.addEventListener(LMouseEvent.MOUSE_UP,selectToPrevious);
	selectLayer.addChild(selectButton);
	selectButton = getButton01("下");
	selectButton.x = 95;
	selectButton.y = 320;
	selectButton.addEventListener(LMouseEvent.MOUSE_UP,selectToNext);
	selectLayer.addChild(selectButton);
	
	selectButton = getButton02("选择");
	selectButton.x = 600;
	selectButton.y = 320;
	selectLayer.addChild(selectButton);
	selectButton.addEventListener(LMouseEvent.MOUSE_UP,selectToStartGame);
}
SelectMap.prototype.showList=function(){
	var self = this,nameBtn,nameTxt,face,index,h=0;
	listLayer.die();
	listLayer.removeAllChild();
	index = self.selectIndex;
	listLayer.x = listLayer.y= 20;
	for(var i=index,j=0;i<index+3 && i < monarch.length;i++,j++){
		nameBtn = new LBitmap(new LBitmapData(datalist['nameBtn'],0,0,144,34));
		nameBtn.y = j*(34 + 60);
		listLayer.addChild(nameBtn);
		nameTxt = new LTextField();
		nameTxt.text = characterList[monarch[i].monarchIndex].name;
		nameTxt.color = "#FFFFFF";
		nameTxt.size = 14;
		nameTxt.x = nameBtn.x + (nameBtn.getWidth() - nameTxt.getWidth())*0.5;
		nameTxt.y = nameBtn.y;
		listLayer.addChild(nameTxt);
		face = new Face(characterList[monarch[i].monarchIndex].img);
		face.scaleX = face.scaleY = 0.5;
		face.x = 45;
		face.y = 26 + nameBtn.y;
		listLayer.addChild(face);
		h += (34 + 60);
	}
	listLayer.graphics.drawRect(0,"#999999",[0,0,144,h],true,"#333333");
	listLayer.addEventListener(LMouseEvent.MOUSE_UP,clickList);
}
SelectMap.prototype.showMiniMap=function(){
	var miniMap = new LBitmap(new LBitmapData(datalist['minimap']));
	miniMap.x = 180;
	cityLayer.addChild(miniMap);
}
SelectMap.prototype.layerInit=function(){
	var self = this;
	backLayer = new LSprite();
	self.addChild(backLayer);

	listLayer = new LSprite();
	self.addChild(listLayer);

	cityLayer = new LSprite();
	self.addChild(cityLayer);
	
	selectLayer = new LSprite();
	self.addChild(selectLayer);

	selectedLayer = new LSprite();
	self.addChild(selectedLayer);
}